class AppartsController < ApplicationController
  # GET /apparts
  # GET /apparts.xml
  def index
    @apparts = Appart.find(:all)
    @moycarre = Appart.MoyMetreCarre
    
    respond_to do |format|
      format.html # index.rhtml
      format.xml  { render :xml => @apparts.to_xml }
    end
  end

  # GET /apparts/1
  # GET /apparts/1.xml
  def show
    @appart = Appart.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @appart.to_xml }
    end
  end

  # GET /apparts/new
  def new
    @appart = Appart.new
    @ville = Villes.find(:all)
  end

  # GET /apparts/1;edit
  def edit
    @appart = Appart.find(params[:id])
    @ville = Villes.find(:all)
  end

  # POST /apparts
  # POST /apparts.xml
  def create
    @appart = Appart.new(params[:appart])
    @ville = Villes.find(:all)
    
    respond_to do |format|
      if @appart.save
        flash[:notice] = 'Appart was successfully created.'
        format.html { redirect_to appart_url(@appart) }
        format.xml  { head :created, :location => appart_url(@appart) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @appart.errors.to_xml }
      end
    end
  end

  # PUT /apparts/1
  # PUT /apparts/1.xml
  def update
    @appart = Appart.find(params[:id])
    @ville = Villes.find(:all)

    respond_to do |format|
      if @appart.update_attributes(params[:appart])
        flash[:notice] = 'Appart was successfully updated.'
        format.html { redirect_to appart_url(@appart) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @appart.errors.to_xml }
      end
    end
  end

  # DELETE /apparts/1
  # DELETE /apparts/1.xml
  def destroy
    @appart = Appart.find(params[:id])
    @appart.destroy

    respond_to do |format|
      format.html { redirect_to apparts_url }
      format.xml  { head :ok }
    end
  end
end
